<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="${_css}/custom.css" rel="stylesheet">
    <link href="${_css}/icheck/flat/green.css" rel="stylesheet">
    <link href="${_js}/datetimepicker/datetimepicker.css" rel="stylesheet">
    <script src="${_js}/jquery.min.js"></script>


</head>


<body style="background: #F7F7F7;" class="nav-md">

	<div class="">
        <div class="row" id="main-row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>发布新手标</h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">

                        <form class="form-horizontal">
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="password">借款标题
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	<input type="text" id="title" class="form-control col-md-7 col-xs-12">
                                </div>
                            </div>    
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">借款金额
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="amount"  class="form-control col-md-7 col-xs-7" 
                                    onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   >
                                </div>
                            </div>              
                            <!--                
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="assuranceProvider">担保方
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	<input type="text" id="assuranceProvider" class="form-control col-md-7 col-xs-12">说明借款担保方。
                                </div>
                            </div>
                            -->  
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="password">借款期限(天)
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	<input type="text" id="date" class="form-control col-md-7 col-xs-12" 
                                	 onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" 
                                	>借款成功后,打算以几个月的时间来还清贷款。
                                </div>
                            </div>                                                                                   
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">还款方式
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <select class="form-control" id="paymentMode">
                                        <option value="0">一次性还款</option>
                                    </select>
                                                                                                           一次性还款是指贷款者借款成功后一次性还清本金和利息
                                </div>
                            </div>                        
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">年化率
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="precent" class="form-control col-md-7 col-xs-12" 
                                    onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   >借款标的年化收益率
                                </div>
                            </div> 
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">最小投标金额
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="min" class="form-control col-md-7 col-xs-12" 
                                   onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   >对投资者对一个借款标的最低投标总额的限制
                                </div>
                            </div> 
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">最大投标金额
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="max" class="form-control col-md-7 col-xs-12" 
                                   onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   >允许投资者对一个借款标的投标总额的限制
                                </div>
                            </div>  
                            <div class="item form-group">
						        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-single_cal2">定时显示时间</label>
						        <div class="col-md-3 col-sm-3 col-xs-6">
						            <input style="width: 376.75px;margin-left: 0px;" data-date-format="yyyy-mm-dd hh:ii:ss" readonly 
						            class="form-control col-md-7 col-xs-12 form_datetime" data-val="true"
						             id="single_cal2" type="text" value="" />
						        </div>
						    </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="row" style="margin-bottom:50px">
        	<div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-6 col-md-offset-5">
                        <button type="button" onclick="javascript:history.go(-1)" class="btn btn-primary">返回前一页</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" id="btn-submit" class="btn btn-success">确认发布</button>
                    </div>
    			</div>
        	</div>       
		</div>
	</div>

    <script src="${_js}/bootstrap.min.js"></script>
    <!-- bootstrap progress js -->
	<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
	<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
    
	<script src="${_js}/custom.js" type="text/javascript"></script>
            
	<!-- PNotify -->
	<script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>  
	
	<!-- daterangepicker -->
	<script type="text/javascript" src="${_js}/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"></script>
	<script type="text/javascript" src="${_js}/datetimepicker/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script>
	<script type="text/javascript" src="${_js}/datetimepicker/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
    <script type="text/javascript">
	 $(document).ready(function () {
        $('.form_datetime').datetimepicker({
	        language:  'zh-CN', 
            showMeridian: true,
        	autoclose: true,
        	todayBtn: true
	    });
    });
    
   $("#btn-submit").click(function(){
   		var title=$.trim($("#title").val());
   		var amount=$.trim($("#amount").val());
   		var date=$.trim($("#date").val());
   		var paymentMode=$.trim($("#paymentMode").val());
   		var percent=$.trim($("#precent").val());
   		var min=$.trim($("#min").val());
   		var max=$.trim($("#max").val());
   		//var assuranceProvider = $.trim($("#assuranceProvider").val());
   		var timingShow = $.trim($("#single_cal2").val());
   		if(title == ""){
   			new PNotify({
		            	title: '操作提示',
		            	text: '借款标题不能为空',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		/**
   		if(assuranceProvider == ""){
   			new PNotify({
		            	title: '操作提示',
		            	text: '担保方不能为空',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		**/
   		if(amount == "" || parseFloat(amount)<=0){
   			new PNotify({
		            	title: '操作提示',
		            	text: '借款金额为空或输入错误',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		if(date == "" || parseInt(date)<=0){
   			new PNotify({
		            	title: '操作提示',
		            	text: '借款期限为空或输入错误',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		if(precent == "" || parseInt(precent)<=0){
   			new PNotify({
		            	title: '操作提示',
		            	text: '年化率为空或输入错误',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		var borrow=JSON.stringify({
   			title:title,
   			amount:amount,
   			percent:percent,
   			deadline:date,
   			paymentMode:paymentMode,
   			min:min,
   			max:max,
   			timingShow:timingShow
   		});
   		
   		$.ajax({
            type: 'post',
            dataType: 'JSON',
            async:'false',
            headers: {'Content-type': 'application/json;charset=UTF-8'},
            url: '/admin/borrow/new/save',
            data:borrow,
            success: function(result){
           		 if(result.code==-1){
             	    new PNotify({
		            	title: '操作提示',
		            	text: '发布成功!',
		            	delay: 3e3,
		            	type: 'success'
		        	});
		        	window.location.href="/admin/borrow/listNewBorrow";	            		 	
           		 }else{
           		 	if(result.code == 0){
		        		alert("请先登录！");
						top.location.href = "/admin/login";
		        	}else{
	              	    new PNotify({
			            	title: '操作提示',
			            	text: result.msg,
			            	delay: 3e3,
			            	type: 'error'
			        	});
			        	return false;  
		        	}        		 
           		 }
            }
        });    
   }) 
   </script>
    
</body>
</html>